package com.ruoyi.womp.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("commdict")
public class CommonDictService {

	@Autowired
	ISqlQueryService sqlQueryService;

	public List<Map<String, Object>> getDictList(String params) {

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		if (null != params && params.length() > 0) {
			params = params.replaceAll("semicolon", "'");
			String[] arr = params.split(",");
			if (params.length() >= 3) {
				String tableName = arr[0];
				String dictValue = arr[1];
				String dictLabel = arr[2];
				String where = arr.length > 3 ? arr[3] : "";
				String order = arr.length > 4 ? arr[4] : "";

				StringBuffer sb = new StringBuffer();
				sb.append("select ").append(dictValue).append(" dictValue,").append(dictLabel).append(" dictLabel ")
						.append(" from ").append(tableName);

				if (null != where && where.length() > 0) {
					sb.append(" where ").append(where);
				}

				if (null != order && order.length() > 0) {
					sb.append(" " + order);
				}

				list = sqlQueryService.queryMapList(sb.toString());
			}
		}

		return list;
	}
}
